<?php

namespace common\widgets;

use Yii;

class DateTimePicker extends \kartik\datetime\DateTimePicker
{

    /**
     * @var string
     */
    public $displayFormat = 'Y-m-d H:i:s';

    /**
     * @var bool 自动转换格式
     */
    public $convertFormat = true;

    /**
     * @var array
     */
    public $pluginOptions = [
        'format' => 'php:Y-m-d H:i:s',
        'todayBtn' => true,
        'todayHighlight' => true,
        'autoclose' => true,
    ];

    /**
     * {@inheritdoc}
     */
    protected function renderInput()
    {
        if ($this->displayFormat && is_numeric($this->value))
        {
            $this->model->{$this->attribute} = $this->value = date($this->displayFormat, $this->value);
        }
        return parent::renderInput();
    }
}
